<template>
	<view>
		<view class="wrap">
			<view class="u-tabs-box flex-start">
				<view v-for="(item, index) in list" :key="`list${index}`" :class="[current === index && 'head-item-active', 'head-item']" @click="clickEvent(index)">
					<u-badge v-if="index === 0 && result1 || index === 1 && result2 || index === 2 && result3 ||index === 3 && result4" :is-center="true" type="warning "  :is-dot="true"></u-badge>
					<span>{{ item.name }}</span>
				</view>
			</view>
			<view class="page-box" v-if="current === 0 || current === 1">
				<view class="order">
					<view class="item" v-for="(item, index) in orderList" :key="index" @click.stop="goToNext(current, item)">
						<view class="left">
							<u-avatar level-size="90" :level-icon="item.starFlag === '1' ? '/static/img/community/ic_daka.png' : ''"
								:show-level=true mode="circle" :src="img_url + item.avatar" img-mode="aspectFill">
							</u-avatar>
						</view>
						<view class="content">
							<view class="title-line u-line-2">
								<view class="title">{{ item.nickName }}</view>
								<view class="title-time">{{ item.sendTime }}</view>
							</view>
							<view class='info-line'>
								<text>{{item.content}}</text>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="page-box" v-if="current === 3 || current === 2">
				<view class="order">
					<view class="item-jubao" v-for="(item, index) in orderList" :key="index" @click.stop="tap">
						<view class="jubao-text" v-if="current === 2">{{ item.content }}</view>
						<view class="jubao-text" v-else>{{ item.content }}</view>
						<view class="jubao-time flex-between">
							<view>{{ item.sendTime }}</view>
							<view class="look-mesage" @click="showEvent(item)" v-if="item.operationType === '02' || item.operationType === '05' || item.operationType === '07' || item.operationType === '21'">查看修改意见</view>
							<view class="look-mesage" @click="showEvent(item)" v-if="item.operationType === '03'">查看下架原因</view>
						</view>
					</view>
				</view>
			</view>
			<view class="no-data-wrapper" v-if="!orderList.length && noDataFlag">
				<img class="no-image" src="/static/img/message_no.png" alt="" srcset="">
				<view class="text-top">暂无消息</view>
				<view class="text-bottom">您还没有收到消息哦</view>
			</view>
		</view>
		<u-modal v-model="tishow" width="70%" title="修改意见">
			<view class="slot-content">
				{{ content }}
			</view>
		</u-modal>
	</view>
</template>

<script>
	import apis from '@/apis.js'
	import {
		mapState,
		mapActions,
		mapMutations
	} from 'vuex'
	export default {
		data() {
			return {
				noDataFlag: false,
				tishow: false,
				content: '',
				orderList: [],
				list: [{
						name: '私信'
					},
					{
						name: '关注'
					},
					{
						name: '举报'
					},
					{
						name: '系统'
					},
					{
						name: '评论'
					}
				],
				current: 0,
				listQuery: {
					newsType: 1, // 1、2、3、4
					pageNo: 1,
					pageSize: 10
				},
				result1: 0,
				result2: 0,
				result3: 0,
				result4: 0,
				isFirst: true
				
			};
		},
		computed: {
			...mapState(['img_url']),
		},
		onLoad() {
			this.getList()
			this.getUnReadNumber()
		},
		methods: {
			tap() {},
			showEvent(item) {
				
				if (item.remark) {
					this.content = item.remark
					this.tishow = true
				}
				
			},
			/**
			 * @function 判断是跳转到私信和个人主页
			 * @param {Object} current 当前tab的下标
			 * @param {Object} item 当前点击的数据
			 */
			goToNext(current, item) {
				if (current) {
					this.$u.route({
						url: "pages/tabbar/tabbar-1/personHome",
						params: {
							id: item.sendUserId
						}
					})
				} else {
					this.$u.route({
						url: "pages/tabbar/tabbar-1/direct-message",
						params: {
							id: item.sendUserId,
				  			name: item.nickName,
							avatar: item.avatar
						}
					})
				}
				
			},
			getUnReadNumber() {
				this.$http.get(apis.getCountUnReadNewsRecordByType, { newsType: 1 }).then(res => {
					if (res.data.code === 200) {
						this.result1 = res.data.result
					}
				})
				this.$http.get(apis.getCountUnReadNewsRecordByType, { newsType: 2 }).then(res => {
					if (res.data.code === 200) {
						this.result2 = res.data.result
					}
				})
				this.$http.get(apis.getCountUnReadNewsRecordByType, { newsType: 3 }).then(res => {
					if (res.data.code === 200) {
						this.result3 = res.data.result
					}
				})
				this.$http.get(apis.getCountUnReadNewsRecordByType, { newsType: 4 }).then(res => {
					if (res.data.code === 200) {
						this.result4 = res.data.result
					}
				})
			},
			/**
			 *  @description  获取数据
			 */
			getList() {
				if (!this.isFirst) {
					this.$http.post(apis.changeNewsRecordRead, this.listQuery).then(res => {
					if (res.data.code === 200) {
						if (this.listQuery.newsType === 1) {
							this.result1 = 0
						} else if (this.listQuery.newsType === 2) {
							this.result2 = 0
						} else if (this.listQuery.newsType === 3) {
							this.result3 = 0
						} else if (this.listQuery.newsType === 4) {
							this.result4 = 0
						}
						
					}
				})
				}
				this.isFirst = false
				this.noDataFlag = false
				this.$http.get(apis.getNewsRecordListByType, this.listQuery).then(res => {
					if (res.data.code === 200) {
						this.noDataFlag = true
						this.orderList = this.orderList.concat(res.data.result.records)
					}
				})
			},
			/**
			 * @function 当前点击的下标
			 * @param {Object} index 当前点击的下标
			 */
			clickEvent(index) {
				this.current = index
				this.listQuery.newsType = index + 1
				this.listQuery.pageNo = 1
				this.orderList = []
				
				this.getList()
			},
		},
		onReachBottom() {
			this.listQuery.pageNo += 1
			this.getList()
		}
	};
</script>

<style>
	/* #ifndef H5 */
	/* 	page {
		height: 100%;
		background-color: #f2f2f2;
	} */

	/* #endif */
</style>

<style lang="scss" scoped>
	.slot-content {
		padding: 20px;
	}
	.look-mesage{
		font-size: 14px;
	}
	.u-tabs-box{
		width: 100%;
		padding: 0 20px;
		margin-top: 30px;
		.head-item {
			font-size: 32rpx;
			margin: 0 20rpx;
			color: rgb(48, 49, 51);
			position: relative;
		}
		.head-item-active {
			color: rgb(33, 210, 255);
			font-size: 36rpx;
			font-weight: bold;
		}
	}
	/* 	.tabs-swiper1 {
		border: 2rpx solid #949494;
		opacity: 1;
	} */

	.order {
		width: 710rpx;
		background-color: #ffffff;
		margin: 20rpx auto;
		border-radius: 20rpx;
		box-sizing: border-box;
		font-size: 28rpx;

		.top {
			display: flex;
			justify-content: space-between;

			.left {
				display: flex;
				align-items: center;

				.store {
					margin: 0 10rpx;
					font-size: 32rpx;
					font-weight: bold;
				}
			}

			.right {
				color: $u-type-warning-dark;
			}
		}

		.item {
			display: flex;
			margin: 20rpx 0 0;
			border-bottom: 2rpx solid #BFBFBF;
			padding-bottom: 35rpx;
			padding-top: 25rpx;

			.left {
				margin-right: 20rpx;

				image {
					width: 200rpx;
					height: 200rpx;
					border-radius: 10rpx;
				}
			}

			.content {
				display: flex;
				flex-flow: column nowrap;
				flex-grow: 2;

				.title-line {
					// background-color: red;
					display: flex;
					flex-flow: row nowrap;

					.title {
						flex-shrink: 2;
						width: 350rpx;
						color: #4D5B80;
						opacity: 1;

						// display: -webkit-box;
						// /* -webkit-box-orient: vertical; */
						// /*! autoprefixer: off */
						// -webkit-box-orient: vertical;
						// /* autoprefixer: on */
						// //超出多少行显示省略号
						// -webkit-line-clamp: 1;
						// overflow: hidden;
						// white-space: nowrap;
						//     text-overflow:ellipsis; 
						overflow: hidden;
						text-overflow: ellipsis;
						display: -webkit-box;
						-webkit-line-clamp: 1;
						-webkit-box-orient: vertical;
					}

					.title-time {
						flex-grow: 2;
						font-size: 23rpx;
						font-family: SimHei;
						font-weight: 400;
						color: #949494;
						opacity: 1;
						margin-left: 10rpx;
						text-align: right;
					}
				}

				.info-line {
					margin-top: 36rpx;

					text {
						font-size: 23rpx;
						font-family: SimHei;
						font-weight: 400;
						color: #4D5B80;
						opacity: 1;

						overflow: hidden;
						text-overflow: ellipsis;
						display: -webkit-box;
						-webkit-line-clamp: 1;
						-webkit-box-orient: vertical;
						// text-align: justify;
					}
				}

				.type {
					margin: 10rpx 0;
					font-size: 24rpx;
					color: $u-tips-color;
				}

				.delivery-time {
					color: #e5d001;
					font-size: 24rpx;
				}


			}

			.right {
				margin-left: 10rpx;
				padding-top: 20rpx;

				text-align: right;

				.decimal {
					font-size: 24rpx;
					margin-top: 4rpx;
				}

				.number {
					color: $u-tips-color;
					font-size: 24rpx;
				}
			}
			
			
		}
		
		.item-jubao {
			display: flex;
			flex-flow: nowrap column;
			margin: 20rpx 0 0;
			border-bottom: 2rpx solid #BFBFBF;
			padding-bottom: 35rpx;
			padding-top: 25rpx;
			.jubao-text {
				font-size: 31rpx;
				font-family: SimHei;
				font-weight: 400;
				line-height: 40rpx;
				color: #4D5B80;
				margin: 20rpx 18rpx;
				opacity: 1;
				margin-left: 0;
			}
			
			.jubao-time {
				width: 100%;
				align-self: flex-end;
				font-size: 23rpx;
				font-family: SimHei;
				font-weight: 400;
				color: #949494;
				opacity: 1;
			}
		}

		.total {
			margin-top: 20rpx;
			text-align: right;
			font-size: 24rpx;

			.total-price {
				font-size: 32rpx;
			}
		}

		.bottom {
			display: flex;
			margin-top: 40rpx;
			padding: 0 10rpx;
			justify-content: space-between;
			align-items: center;

			.btn {
				line-height: 52rpx;
				width: 160rpx;
				border-radius: 26rpx;
				border: 2rpx solid $u-border-color;
				font-size: 26rpx;
				text-align: center;
				color: $u-type-info-dark;
			}

			.evaluate {
				color: $u-type-warning-dark;
				border-color: $u-type-warning-dark;
			}
		}
	}

	.centre {
		text-align: center;
		margin: 200rpx auto;
		font-size: 32rpx;

		image {
			width: 164rpx;
			height: 164rpx;
			border-radius: 50%;
			margin-bottom: 20rpx;
		}

		.tips {
			font-size: 24rpx;
			color: #999999;
			margin-top: 20rpx;
		}

		.btn {
			margin: 80rpx auto;
			width: 200rpx;
			border-radius: 32rpx;
			line-height: 64rpx;
			color: #ffffff;
			font-size: 26rpx;
			background: linear-gradient(270deg, rgba(249, 116, 90, 1) 0%, rgba(255, 158, 1, 1) 100%);
		}
	}

	.wrap {
		display: flex;
		flex-direction: column;
		height: calc(100vh - var(--window-top));
		width: 100%;
	}

	.swiper-box {
		flex: 1;
	}

	.swiper-item {
		height: 100%;
	}
	.no-data-wrapper {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		margin-top: 228rpx;
		.no-image {
			width: 369rpx;
			height: 229rpx;	
			margin-bottom: 43rpx;
		}
		.text-top {
			font-size: 36rpx;
			font-family: Source Han Sans CN;
			font-weight: 500;
			color: #212121;
			margin-bottom: 34rpx;
		}
		.text-bottom {
			font-size: 28rpx;
			font-family: Source Han Sans CN;
			font-weight: 500;
			color: #707070;
		}
	}
</style>
